/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.wsapi.chat;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.DestinationVariable;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Controller;

/**
 *
 * @author yangyan <y.os@qq.com>
 */
@Controller
public class ChatController {

    private SimpMessagingTemplate template;
//
//    @Autowired
//    public ChatController(SimpMessagingTemplate template) {
//        this.template = template;
//    }

    @MessageMapping("/send/${toUser}")
    public void handle(@DestinationVariable("toUser") String toUser, String greeting) {
        String text = "[" + System.currentTimeMillis() + "]:" + greeting;
        this.template.convertAndSend("/topic/greetings", text);
    }

}
